//
//  TeacherDetailPJV.m
//  HTP
//
//  Created by admin on 15/11/9.
//  Copyright © 2015年 nit. All rights reserved.
//

#import "TeacherDetailPJV.h"
@interface TeacherDetailPJV()
@property (nonatomic,retain) UILabel *phoneLaebl;
@property (nonatomic,retain) UILabel *contentLabel;
@property (nonatomic,retain) UILabel *courseLabel;
@property (nonatomic,retain) UIImageView *lineImage;
@end

@implementation TeacherDetailPJV
-(id)init{
    self = [super init];
    if (self) {
        [self _initView];
    }
    return self;
}
-(void)_initView{
    _phoneLaebl = [self getNormolLabel];
    _phoneLaebl.textAlignment = _TEXT_ALIGN_LEFT;
    [self addSubview:_phoneLaebl];
    _contentLabel = [self getNormolLabel];
    _contentLabel.textAlignment = _TEXT_ALIGN_LEFT;
    [self addSubview:_contentLabel];
    _courseLabel = [self getNormolLabel];
    _courseLabel.font = [UIFont systemFontOfSize:13];
    [self addSubview:_courseLabel];
    
    _lineImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"line_h"]];
    [self addSubview:_lineImage];
}
-(UILabel *)getNormolLabel{
    UILabel *label = [[UILabel alloc] init];
    label.textAlignment = _TEXT_ALIGN_CENTER;
    label.font = [UIFont systemFontOfSize:15];
    label.textColor = RGBCOLOR(0, 0, 0, 0.7);
    label.numberOfLines = 0;
    return label;
}
-(CGFloat)TeacherPJRecordModel:(TeacherPJRecordModel *)teacherPJRecordModel{
    _teacherPJRecordModel = teacherPJRecordModel;
    
    [_phoneLaebl setText:[self getHiddenPhone:_teacherPJRecordModel.parentPhone]];
    [_phoneLaebl setFrame:CGRectMake(20, 0, ScreenWidth, 20)];
    [self getHiddenPhone:_teacherPJRecordModel.parentPhone];
    [_contentLabel setText:[NSString stringWithFormat:@"%@",_teacherPJRecordModel.crAccessContent]];
    _contentLabel.frame = CGRectMake(20, CGRectGetMaxY(_phoneLaebl.frame)+10, ScreenWidth - 40, [_contentLabel.text textSizeWithFont:_contentLabel.font constrainedSize:CGSizeMake(ScreenWidth - 40, 20000)].height);
    
    [_courseLabel setText:[NSString stringWithFormat:@"%@%@",_teacherPJRecordModel.grade,_teacherPJRecordModel.course]];
    _courseLabel.textAlignment = _TEXT_ALIGN_RIGHT;
    [_courseLabel setFrame:CGRectMake(20, CGRectGetMaxY(_contentLabel.frame)+10, ScreenWidth - 40, 20)];
    
    
    if (!_isLast) {
        [_lineImage setFrame:CGRectMake(20, CGRectGetMaxY(_courseLabel.frame) + 9, ScreenWidth - 40, 1)];
    }else{
        [_lineImage removeFromSuperview];
    }
    return CGRectGetMaxY(_courseLabel.frame) + 10;
    
    
}
-(NSString *)getHiddenPhone:(NSString *)phone{
    NSString *hiddenPhone;
    if (phone.length > 5) {
        int last =(int) (phone.length - 5) / 2;
        NSString *s_1 = [phone substringWithRange:NSMakeRange(0, last)];
        
        NSString *s_2 = [phone substringWithRange:NSMakeRange(last + 5, phone.length - last - 5 )];
        
        hiddenPhone = [NSString stringWithFormat:@"%@*****%@",s_1,s_2];
    }
    return hiddenPhone;
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
